package com.itheima.controller;


import com.itheima.aliyunoss.AliyunUtils;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.poi.POIUtils;
import com.itheima.pojo.Setmeal;
import com.itheima.pub.MessageConstant;
import com.itheima.pub.RedisConstant;
import com.itheima.service.OrdersettingService;
import com.itheima.service.SetmealService;
import com.itheima.upload.UploadUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("ordersetting")
public class OrdersettingController {
    @Reference
    private OrdersettingService ordersettingService;

    @RequestMapping("importOrderSettings")
    public Result importOrderSettings(@RequestParam("excelFile")MultipartFile file){
        try {
            List<String[]> list = POIUtils.readExcel(file);
            ordersettingService.importOrderSettings(list);
            return new Result(true,MessageConstant.IMPORT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.IMPORT_ORDERSETTING_FAIL);
        }

    }

    @RequestMapping("findOrderSettingsData")
    public Result findOrderSettingsData(@RequestParam("yearAndMonth")String yearAndMonth){
        try {
            List<Map> list = ordersettingService.findOrderSettingsData(yearAndMonth);
            return new Result(true,MessageConstant.QUERY_ORDERSETTING_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_ORDERSETTING_FAIL);
        }
    }

    @RequestMapping("updateOrderSettingData")
    public Result updateOrderSettingData(@RequestParam("dateparam")String dateparam,@RequestParam("num")Integer num){
        try {
            ordersettingService.updateOrderSettingData(dateparam,num);
            return new Result(true,MessageConstant.EDIT_ORDERSETTING_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_ORDERSETTING_FAIL);
        }
    }
}
